<template>
	<!-- <el-button v-if="isImg" size="small" text type="primary" @click="showFile()"><View style="width: 1em; height: 1em; margin-right: 8px" />查看</el-button> -->
	<el-button size="small" text type="primary" @click="showFile()"><View style="width: 1em; height: 1em; margin-right: 8px" />下载</el-button>
</template>
<script setup>
import { reactive, onMounted, ref, computed } from 'vue';
import {View} from "@element-plus/icons-vue"

const props = defineProps({
	url: {
		type: String,
	},
	name: {
		type: String
	}
})

const isImg = computed(() => {
	let arr = props.url.split('.');
	let suffix = arr[arr.length - 1];

	return ['png', 'jpg', 'jpeg', 'gif'].includes(suffix);
})

onMounted(() => {
	
})

// 预览文件
const showFile = () => {
	let link = document.createElement('a');
  link.style.display = 'none';
  link.download = props.name;
  link.href = location.origin+'/'+props.url;
  // 触发点击
  document.body.appendChild(link);
  link.click();
  // 然后移除
  document.body.removeChild(link);
}

</script>
<style lang="scss" scoped>

</style>